package testApplets;

import processing.core.PApplet;
import processing.core.PImage;
import simpleGeom.Box3D;

public class ImageExportApplet extends PApplet {
public void setup(){
	Box3D cB=new Box3D(0f,0f,-1.75f,2.0f,3.2f,0f);
	Box3D gridBounds;
	gridBounds=cB.getOffsetBox(0.05f);
	float dim=0.002f;
	// here bullshit
	int  y1=getRoundDown(gridBounds.y1,dim);
	int  x1=getRoundDown(gridBounds.x1,dim);
	int  z1=getRoundDown(gridBounds.z1,dim);
	println("z1: "+z1);
	
	int  y2=getRoundUp(gridBounds.y2,dim);
	int  x2=getRoundUp(gridBounds.x2,dim);
	int  z2=getRoundUp(gridBounds.z2,dim);
	
	float sX=x1*dim;
	float sY=y1*dim;
	float sZ=z1*dim;
	 int nX=x2-x1;
	 int nY=y2-y1;
	int  nZ=z2-z1;
	println("dim: "+dim);
	println("sX: "+sX);
	println("sY: "+sY);
	println("sZ: "+sZ);
	println("nX: "+nX);
	println("nY: "+nY);
	println("nZ: "+nZ);
	
	String voxelPath="/Users/caad/Desktop/Final Shape/Iteration10/Voxel_Distance";
	VoxelStream vStream=new VoxelStream(voxelPath);
	
	float[] values=new float[nX*nZ];
	PImage img=this.createImage(nZ,nX,RGB);
	
	for (int i=0;i<1600;i+=10){
		vStream.loadValuesBinary(i, values);
		img.loadPixels();
		for (int j=0;j<values.length;j++){
			float cValue=values[j];
			if (cValue<dim*0.9F){
				img.pixels[j]=this.color(255);
			}
			else{
				img.pixels[j]=this.color(0);
			}
		}
		img.updatePixels();
		img.save("/Users/caad/Desktop/Final Shape/Iteration10/Voxel_Images/"+i+".png");
	}
}
public int getRoundDown(float value,float dim){
	return (int)(value/dim);
}
public int getRoundUp(float value,float dim){
	return (int)(value/dim)+1;
}
}
